package com.demo.controller;

import com.demo.dao.StudentRepository;
import com.demo.pojo.Student;
import com.demo.service.StudentService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName StudentController
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/17 10:27
 * @Version 1.0
 **/
@RestController
@RequestMapping("stu")
public class StudentController {
    @Autowired
    StudentService service;



    @RequestMapping("findAll")
    @RequiresPermissions(value = {"findAll"})
    public List<Student> findAll() {
        List<Student> all = service.findAll();
        System.out.println(all);
        return all;
    }
    @RequestMapping("del")
    @RequiresPermissions(value = {"del"})
    public String del(int id){
        boolean b = service.delStudent(id);
        if (b) {
            return "success";
        }
        return "fail";
    }
    @RequestMapping("findOne")
    public Student findOne(int id){
        return service.findOne(id);
    }

    @RequestMapping("editStu")
    @RequiresPermissions(value = {"edit"},logical = Logical.OR)
    public String editStu(@RequestBody Student student){
        boolean b = service.editStu(student);
        if (b) {
            return "success";
        }
        return "fail";
    }

    @RequestMapping("addStu")
    @RequiresPermissions(value = {"add"},logical = Logical.OR)
    public String addStu(@RequestBody Student student){
        boolean b = service.editStu(student);
        if (b) {
            return "success";
        }
        return "fail";
    }
}
